//
//  HLESessionManager.h
//  HLENetwork_Example
//
//  Created by hle1879 on 2020/9/30.
//  Copyright © 2020 13434436448@163.com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "HLENetWorkConfig.h"

@class AFHTTPSessionManager;
@class HLEBaseRequest;
@class HLEImageUploadRequest;
@class HLEFileUploadRequest;
@class HLEDownloadRequest;
@class HLEBaseResponse;
@class HLEDownLoadResponse;

NS_ASSUME_NONNULL_BEGIN

@interface HLESessionManager : NSObject

@property (nonatomic,strong,readonly)AFHTTPSessionManager *sessionManager;
@property (nonatomic,strong,readonly)HLENetWorkConfig *config;
///所有的请求
@property (nonatomic,strong,readonly) NSMutableArray<HLEBaseRequest*> *allRequests;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

///创建默认配置
+ (instancetype)defaultManager;

///创建自定义的配置
+ (instancetype)initWithConfig:(HLENetWorkConfig*)config;

///是否开启日志
- (void)enableLog:(BOOL)enable;

///发送请求,不带请求头和缓存策略
- (HLEBaseRequest *)url:(NSString *)URLString method:(HLENetWorkRequestMethod)method parameters:(nullable NSDictionary*)parameters  completion:(nullable void (^)(HLEBaseResponse * _Nonnull response))completion;

///发送请求,带请求头但不带缓存策略
- (HLEBaseRequest *)url:(NSString *)URLString method:(HLENetWorkRequestMethod)method parameters:(nullable NSDictionary*)parameters requestHeader:(nullable NSDictionary*)requestHeader completion:(nullable void (^)(HLEBaseResponse * _Nonnull response))completion;

///发送请求,带缓存策略但不带请求头
- (HLEBaseRequest *)url:(NSString *)URLString method:(HLENetWorkRequestMethod)method parameters:(nullable NSDictionary*)parameters cachePolicy:(HLENetWorkCachePolicy)cachePolicy  cacheValidTime:(NSTimeInterval)validTime cacheCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))cacheCompletion responseCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))responseCompletion;

///发送请求,带请求头和缓存策略
- (HLEBaseRequest *)url:(NSString *)URLString method:(HLENetWorkRequestMethod)method parameters:(nullable NSDictionary*)parameters  requestHeader:(nullable NSDictionary*)requestHeader cachePolicy:(HLENetWorkCachePolicy)cachePolicy  cacheValidTime:(NSTimeInterval)validTime cacheCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))cacheCompletion responseCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))responseCompletion;


///上传图片
- (HLEImageUploadRequest *)url:(NSString *)URLString parameters:(nullable NSDictionary*)parameters  requestHeader:(nullable NSDictionary*)requestHeader images:(nonnull NSArray *)images imageScale:(CGFloat)imageScale imageFileName:(nullable NSString*)imageFileName name:(nullable NSString*)name imageType:(nullable NSString*)imageType progress:(nullable void (^)(NSProgress * _Nonnull progress,double progressRate))progress responseCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))responseCompletion;


///上传文件
- (HLEFileUploadRequest *)url:(NSString *)URLString parameters:(nullable NSDictionary*)parameters  requestHeader:(nullable NSDictionary*)requestHeader filePath:(nonnull NSString *)filePath  name:(nullable NSString*)name progress:(nullable void (^)(NSProgress * _Nonnull progress,double progressRate))progress responseCompletion:(nullable void (^)(HLEBaseResponse * _Nonnull response))responseCompletion;

///下载文件
- (HLEDownloadRequest *)url:(NSString *)URLString requestHeader:(nullable NSDictionary*)requestHeader folderName:(nonnull NSString *)folderName progress:(nullable void (^)(NSProgress * _Nonnull progress,double progressRate))progress responseCompletion:(nullable void (^)(HLEDownLoadResponse * _Nonnull response))responseCompletion;

///断点下载
- (HLEDownloadRequest *)resumeData:(nonnull NSData *)resumeData requestHeader:(nullable NSDictionary*)requestHeader folderName:(nonnull NSString *)folderName progress:(nullable void (^)(NSProgress * _Nonnull progress,double progressRate))progress responseCompletion:(nullable void (^)(HLEDownLoadResponse * _Nonnull response))responseCompletion;

///取消调用此方法前所有的网络请求
- (void)cancelAllRequest;

///取消所有网络请求并关闭session
- (void)cancelAllRequestStopSessionWithCancelingTasks:(BOOL)cancelPendingTasks;


///移除指定网络请求的数据缓存
- (void)removeCacheWithRequest:(HLEBaseRequest*)request;

///移除指定网络请求的数据缓存带结果回调 (缓存数据量大时移除缓存会占用线程直到移除结束)
- (void)removeCacheWithRequest:(HLEBaseRequest*)request completion:(void(^)(NSString * _Nonnull))completion;

/// 移除所有网络请求数据缓存
- (void)removeAllCache;

/// 移除所有网络请求数据缓存带结果回调 (缓存数据量大时移除缓存会占用线程直到移除结束)
- (void)removeAllCacheWithCompletion:(void(^)(void))completion;

/// 获取网络缓存的总大小 （bytes 字节）
- (NSUInteger)totalCacheSize;

/// 获取网络缓存的总大小  直接返回计算好的B KB MB GB
- (NSString *)totalCacheSizeDescription;

///
@end

NS_ASSUME_NONNULL_END
